package com.shketai.dao;

import java.math.BigInteger;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shketai.entity.Info;
import com.shketai.entity.Student;

public class PaymentDao{
private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	/**
	 * 获取缴费明细
	 */

	public List<Object[]> getPayment(){
		Session session = sessionFactory.getCurrentSession();
		 Query query=session.createSQLQuery("select stu.stuName,sub.subject,c.classname,c.money from Student stu,Subject sub,Classinfo c,Info i where c.subject_id=sub.id and stu.id=i.stu_id and c.id=i.classinfo_id");
		 List<Object[]> list = query.list();
		return  list; 
		
	}
	
	public List<Object[]> getPayment1(int classinfo_id){
		Session session = sessionFactory.getCurrentSession();
		 Query query=session.createSQLQuery("select stu.stuName,sub.subject,c.classname,c.money from Student stu,Subject sub,Classinfo c,Info i where c.subject_id=sub.id and stu.id=i.stu_id and c.id=i.classinfo_id and classinfo_id=?");
		query.setInteger(0, classinfo_id);
		 List<Object[]> list = query.list();
		return  list; 
		
	}
	/**
	 *获取缴费信息进行分页
	 * @param id
	 * @return
	 */
	public List<Object[]> find(int page){
		String sql = " select stu.stuName,sub.subject,c.classname,c.money from Student stu,Subject sub,Classinfo c,Info i where c.subject_id=sub.id and stu.id=i.stu_id and c.id=i.classinfo_id";
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createSQLQuery(sql);
		query.setFirstResult((page-1)*10);
		query.setMaxResults(10);
		List<Object[]> list = query.list();
		return list;
	}
	
	public List<Object[]> find1(int page,int classinfo_id){
		String sql = " select stu.stuName,sub.subject,c.classname,c.money from Student stu,Subject sub,Classinfo c,Info i where c.subject_id=sub.id and stu.id=i.stu_id and c.id=i.classinfo_id and classinfo_id=?";
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createSQLQuery(sql);
		query.setInteger(0, classinfo_id);
		query.setFirstResult((page-1)*10);
		query.setMaxResults(10);
		List<Object[]> list = query.list();
		return list;
	}
	public int findCount() {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createSQLQuery(" select count(*) from Student stu,Subject sub,Classinfo c,Info i where c.subject_id=sub.id and stu.id=i.stu_id and c.id=i.classinfo_id");
		BigInteger total = (BigInteger) query.uniqueResult();
		return total.intValue();
	}

	public int findCount1(int classinfo_id) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createSQLQuery(" select count(*) from Student stu,Subject sub,Classinfo c,Info i where c.subject_id=sub.id and stu.id=i.stu_id and c.id=i.classinfo_id and classinfo_id=?");
		query.setInteger(0, classinfo_id);
		BigInteger total = (BigInteger) query.uniqueResult();
		return total.intValue();
	}
}
